package Gather.ArrayGatherExercise;

import java.util.ArrayList;

/**
 * ClassName:ArrayList003
 * Package:Gather
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/17-23:46
 * @Version:v1.0
 */
public class ArrayList003 {
    /*
    * 需求：定义一个集合,添加字符串,并进行遍历
    * 遍历格式：[元素1,元素2,元素3]*/
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("abc");
        list.add("bcd");
        list.add("cde");
        list.add("def");
        System.out.println(list);

//        StringJoiner sj = new StringJoiner(",","[","]");
        System.out.print("[");
        for (int i = 0; i < list.size(); i++) {
//            sj.add(list.get(i));
            if(i== list.size()-1){
                System.out.print(list.get(i));
            }else {
                System.out.print(list.get(i)+",");
            }
        }
        System.out.println("]");
//        System.out.println(sj);
    }
}
